using System;
using Microsoft.EntityFrameworkCore;

namespace SportsStore.Models;

public class SeedData
{
    public static void EnsurePopulated(IServiceProvider serviceProvider)
    {
        StoreDbContext context = serviceProvider.CreateScope().ServiceProvider.GetRequiredService<StoreDbContext>();

        if (context.Database.GetPendingMigrations().Any())
        {
            context.Database.Migrate();
        }

        if (!context.Products.Any())
        {
            context.Products.AddRange(new Product[]
            {
                new Product { Name = "Kayak", Description = "A boat for one person", Price = 275M, Category = "Watersports", },
                new Product { Name = "Lifejacket", Description = "Protective and fashionable", Price = 48.95M, Category = "Watersports", },
                new Product { Name = "Soccer Ball", Description = "FIFA-approved size and weight", Price = 19.50M, Category = "Soccer", },
                new Product { Name = "Corner Flags", Description = "Give your playing field a professional touch", Price = 34.95M, Category = "Soccer", },
                new Product { Name = "Stadium", Description = "Flat-packed 35,000-seat stadium", Price = 79500M, Category = "Soccer", },
                new Product { Name = "Thinking Cap", Description = "Improve brain efficiency by 75%", Price = 16M, Category = "Chess", },
                new Product { Name = "Unsteerable Marker", Description = "Waterproof with a 500-foot line", Price = 22M, Category = "Chess", },
                new Product { Name = "Human Chess Board", Description = "A fun game for the family", Price = 75M, Category = "Chess", },
                new Product { Name = "Bling-Bling King", Description = "Gold-plated, diamond-studded King", Price = 1200M, Category = "Chess", }
            });

            context.SaveChanges();
        }
    }
}
